package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SysDevice;
import com.ruoyi.system.domain.SysOrder;
import com.ruoyi.system.domain.SysSale;
import com.ruoyi.system.service.ISysOrderService;
import com.ruoyi.system.service.ISysSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 角色信息
 *
 * @author ruoyi
 */
@Controller
@RequestMapping("/system/order")
public class SysOrderController extends BaseController
{
    @Autowired
    private ISysOrderService orderService;

    @Autowired
    private ISysSaleService saleService;

    @PostMapping("/queryOrderList")
    @ResponseBody
    public TableDataInfo queryOrderList()
    {
        startPage();
        SysOrder order = new SysOrder();
        order.setUserId(getUserId());
        List<SysOrder> list = orderService.selectDeviceList(order);
        return getDataTable(list);
    }

    /**
     * 申请售后
     */
    @GetMapping("/saleAfter/{orderId}")
    public String saleAfter(@PathVariable("orderId") Long orderId, ModelMap mmap)
    {
        mmap.put("order", orderService.selectOrderById(orderId));
        return "common/saleAfter";
    }

    /**
     * 提交申请
     */
    @PostMapping("/apply")
    @ResponseBody
    public AjaxResult apply(@Validated SysSale sale)
    {
        sale.setCreateBy(getLoginName());
        return toAjax(saleService.apply(sale));
    }
}
